package io.github.mymonstercat.utils.baidu;

import com.benjaminwan.ocrlibrary.OcrResult;
import com.benjaminwan.ocrlibrary.TextBlock;
import io.github.mymonstercat.Model;
import io.github.mymonstercat.ocr.InferenceEngine;
import io.github.mymonstercat.ocr.config.HardwareConfig;
import io.github.mymonstercat.ocr.config.ParamConfig;

import java.util.ArrayList;

public class BaiduOCRUtils {

    public static ParamConfig PARAM_CONFIG = ParamConfig.getDefaultConfig();
    public static InferenceEngine ENGINE = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4, new HardwareConfig(Runtime.getRuntime().availableProcessors()/-1, -1));
    static {
        PARAM_CONFIG.setDoAngle(true);
        PARAM_CONFIG.setMostAngle(true);
        PARAM_CONFIG.setPadding(20);
    }

    public static ArrayList<TextBlock> recognizeGeneralText(String filePath){
        OcrResult ocrResult = ENGINE.runOcr(filePath, PARAM_CONFIG);
        ArrayList<TextBlock> arr = ocrResult.getTextBlocks();
        return arr;
    }

    public static void main(String[] args) {
        BaiduOCRUtils.recognizeGeneralText("D:/test/zejiang.jpg");
    }

}
